package com.es.system;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.es.main.LoginUserBeen;
import com.es.util.db.DBBean;
import com.es.util.db.Dao;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
 
 public class ModifyLoginPassword extends ActionSupport
  implements ServletRequestAware
 {
 HttpServletRequest request;

public String execute()
   throws Exception
   {
   this.request.setCharacterEncoding("utf-8");
    HttpSession session = this.request.getSession(false);
	 ModifyPasswordBiz modifyPwdBiz = new ModifyPasswordBiz();
   LoginUserBeen employee = new LoginUserBeen();
    employee = (LoginUserBeen)session.getAttribute("loginuser");

   String oldPasswordFromDb = modifyPwdBiz.getUserPassword(employee.getLoginName());
   String oldPasswordFromJsp = this.request.getParameter("oldPassword").trim();

    String newPassword = this.request.getParameter("newPassword").trim();
  String emp_name = employee.getLoginName().trim();

   if (!oldPasswordFromDb.equals(oldPasswordFromJsp)) {
      String message = "原密码输入错误，修改失败，请从新尝试！";
      this.request.setAttribute("message", message);
      return "false";
   }
 
    String result = modifyPwdBiz.updateLoginPassword(newPassword, emp_name);

    if (result.equals("false")) {
     String message = "修改失败！请从新尝试。";
      this.request.setAttribute("message", message);
     return "false";
     }
    String message = "密码修改成功！";
    this.request.setAttribute("message", message);
 
    return result;
  }

  public void setServletRequest(HttpServletRequest request) {
     this.request = request;
   }

 }
